Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lodash.template

Package Overview
Dependencies
Maintainers
5
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lodash.template

The modern build of lodash’s `_.template` as a module.

  • 3.6.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5M
increased by2.17%
Maintainers
5
Weekly downloads
 
Created

What is lodash.template?

The lodash.template package is a part of the Lodash library which provides utility functions for common programming tasks using the functional programming paradigm. It is specifically designed for creating compiled templates which can be used to interpolate values into strings.

What are lodash.template's main functionalities?

Template Compilation

Compiles templates into functions that can be used to interpolate values. The 'template' function takes a string and returns a compiled template function.

const _ = require('lodash.template');
const compiled = _.template('hello <%= user %>!');
console.log(compiled({ 'user': 'fred' }));
// => 'hello fred!'

HTML Escaping

Supports HTML escaping. The '<%-' sequence in the template string is used to escape values that are interpolated, preventing XSS attacks.

const _ = require('lodash.template');
const compiled = _.template('<b><%- value %></b>');
console.log(compiled({ 'value': '<script>' }));
// => '<b>&lt;script&gt;</b>'

Use of JavaScript Expressions

Allows the use of JavaScript expressions inside templates. This enables iteration and conditional logic within the template string.

const _ = require('lodash.template');
const compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
console.log(compiled({ 'users': ['fred', 'barney'] }));
// => '<li>fred</li><li>barney</li>'

Custom Delimiters

Supports custom delimiters. Users can define their own delimiters for interpolation, evaluation, and escaping.

const _ = require('lodash.template');
const compiled = _.template('hello ${ user }!', { 'interpolate': /\${([\s\S]+?)}/g });
console.log(compiled({ 'user': 'pebbles' }));
// => 'hello pebbles!'

Other packages similar to lodash.template

Keywords

FAQs

Package last updated on 30 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc